package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.List; 
import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXALopMonHocDuKien;
import com.lb.jwitter.service.TblQLDTTXALopMonHocDuKienService;
import com.lb.jwitter.service.TblQLDTTXAMonHoc;
import com.lb.jwitter.service.TblQLDTTXAMonHocService;

import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNam;
import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNamService;

import com.lb.jwitter.service.TblQLDTTXAGiaoVien;
import com.lb.jwitter.service.TblQLDTTXAGiaoVienService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocKyTrongNamtblQLDTTXALopMonHocDuKienInsertAction{
    private Message msg; 
    public Message getMsg() { return msg; }

    private Long id; 
    public void setId(Long id) {
       this.id = id;
 }

    private int monHocId; 
    public void setMonHocId(int monHocId) {
       this.monHocId = monHocId;
 }

    public int getMonHocId() {
       return monHocId;
 }

    private TblQLDTTXAMonHocService tblQLDTTXAMonHocService; 

    private int hocKyId; 
    public void setHocKyId(int hocKyId) {
       this.hocKyId = hocKyId;
 }

    public int getHocKyId() {
       return hocKyId;
 }

    private TblQLDTTXAHocKyTrongNamService tblQLDTTXAHocKyTrongNamService; 

    private int giaoVienId; 
    public void setGiaoVienId(int giaoVienId) {
       this.giaoVienId = giaoVienId;
 }

    public int getGiaoVienId() {
       return giaoVienId;
 }

    private TblQLDTTXAGiaoVienService tblQLDTTXAGiaoVienService; 

    private String ghiChu; 
    public void setGhiChu(String ghiChu) {
       this.ghiChu = ghiChu;
 }

    public String getGhiChu() {
       return ghiChu;
 }
    private String maLop; 
    public void setMaLop(String maLop) {
       this.maLop = maLop;
 }

    public String getMaLop() {
       return maLop;
 }

    private int duocMo; 
    public void setDuocMo(int duocMo) {
       this.duocMo = duocMo;
 }

    public int getDuocMo() {
       return duocMo;
 }

    private TblQLDTTXALopMonHocDuKien tblQLDTTXALopMonHocDuKien; 
    public TblQLDTTXALopMonHocDuKien  getTblQLDTTXALopMonHocDuKien() {
        return tblQLDTTXALopMonHocDuKien;
 }

    private TblQLDTTXALopMonHocDuKienService tblQLDTTXALopMonHocDuKienService; 

	private int preInsert(Message msg, TblQLDTTXALopMonHocDuKien obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postInsert(Message msg, TblQLDTTXALopMonHocDuKien obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_LopMonHoc_DuKien", "them")){ 
        return "noprivilege"; 
 } 
        tblQLDTTXALopMonHocDuKienService = (TblQLDTTXALopMonHocDuKienService) context.getBean("tbl_QLDTTXA_LopMonHoc_DuKienClient"); 
        tblQLDTTXAMonHocService = (TblQLDTTXAMonHocService) context.getBean("tbl_QLDTTXA_MonHocClient"); 

        tblQLDTTXAHocKyTrongNamService = (TblQLDTTXAHocKyTrongNamService) context.getBean("tbl_QLDTTXA_HocKyTrongNamClient"); 

        tblQLDTTXAGiaoVienService = (TblQLDTTXAGiaoVienService) context.getBean("tbl_QLDTTXA_GiaoVienClient"); 

        msg = new Message(); 
        tblQLDTTXALopMonHocDuKien = new TblQLDTTXALopMonHocDuKien(); 
        tblQLDTTXALopMonHocDuKien.setMonHocId(tblQLDTTXAMonHocService.gettblQLDTTXAMonHoc(new Long(monHocId))); 
        tblQLDTTXALopMonHocDuKien.setHocKyId(tblQLDTTXAHocKyTrongNamService.gettblQLDTTXAHocKyTrongNam(new Long(hocKyId))); 
        tblQLDTTXALopMonHocDuKien.setGiaoVienId(tblQLDTTXAGiaoVienService.gettblQLDTTXAGiaoVien(new Long(giaoVienId))); 
        tblQLDTTXALopMonHocDuKien.setGhiChu(ghiChu); 
        tblQLDTTXALopMonHocDuKien.setMaLop(maLop); 
        if(duocMo == 1){ 
           tblQLDTTXALopMonHocDuKien.setDuocMo(true); 
       } else { 
           tblQLDTTXALopMonHocDuKien.setDuocMo(false); 
       } 
        preInsert(msg,tblQLDTTXALopMonHocDuKien); 
       if (msg.isPreMessage_b()) 
       { 
           tblQLDTTXALopMonHocDuKienService.createtblQLDTTXALopMonHocDuKien(tblQLDTTXALopMonHocDuKien); 
           postInsert(msg, tblQLDTTXALopMonHocDuKien); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Insert tbl_QLDTTXA_LopMonHoc_DuKien Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 } 
 } 
 
